package com.aliware.tianchi;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.remoting.Channel;
import org.apache.dubbo.remoting.ChannelHandler;
import org.apache.dubbo.remoting.RemotingException;
import org.apache.dubbo.remoting.transport.dispatcher.all.AllChannelHandler;

import java.util.concurrent.ThreadLocalRandom;

public class GameChannelHandler extends AllChannelHandler {
    public static ThrashConfig configs = null;

    public GameChannelHandler(ChannelHandler handler, URL url) {
        super(handler, url);
    }

    @Override
    public void received(Channel channel, Object message) throws RemotingException {
        if (configs != null && ThreadLocalRandom.current().nextInt(100) < configs.failedProportion) {
            return;
        }
        super.received(channel, message);
    }
}
